<template>
  <div class="search-table-page">
    <table-page :loading="loading"
                :columns1="columns1"
                :data1="tableData"
                :noData="noData"
                :currentPage="currentPage"
                :totalPage="totalPage"
                :pageSize="pageSize"
                @change-page="changePage"
                @change-page-size="changPageSize">
    </table-page>
  </div>
</template>

<script>
import tablePage from '_c/table-page/table-page'
import { getGoodsCommentList } from '@/api/goods'

export default {
  name: 'goods-comment',
  components: {
    tablePage
  },
  data () {
    return {
      exportLoading: false,
      loading: false,
      goAbled: false,
      columns1: [
        {
          type: 'index',
          width: 40,
          align: 'center'
        },
        {
          title: '用户名称',
          key: 'PhoneNum'
        },
        {
          title: '评价时间',
          key: 'CreateTime'
        },
        {
          title: '评价内容',
          key: 'CommentContent',
          tooltip: true,
          align: 'center'
        },
        {
          title: '星级',
          key: 'Star'
        },
        {
          title: '备注',
          key: 'Remark'
        },
        {
          title: '审核状态',
          key: 'AuditState',
          render: (h, params) => {
            const row = params.row
            const text = row.AuditState === 0 ? '未审核' : '已审核'
            return h('span', {}, text)
          }
        }
      ],
      noData: '暂无数据',
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      tableData: [],
      searchData: {
        'PageIndex': '1',
        'PageSize': '10'
      }
    }
  },
  mounted () {
    this.init()
    this.getTableData()
  },
  methods: {
    init () {
      this.searchData = {
        'PageIndex': '1',
        'PageSize': '10'
      }
    },
    // 获取表格数据信息
    getTableData (parameter) {
      this.loading = true
      parameter = this.searchData
      getGoodsCommentList(parameter).then(res => {
        if (res.data.success) {
          this.totalPage = res.data.data.TotalCount
          this.currentPage = res.data.data.CurrentPageIndex
          this.tableData = res.data.data.aaData
          this.loading = false
        } else {
          this.$Message.info(res.data.msg || '缺少必要参数！')
          this.loading = true
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 页码切换
    changePage (page) {
      this.currentPage = page
      this.searchData.PageIndex = page
      this.getTableData()
    },
    // 切换每页显示多少条数据
    changPageSize (pageSize) {
      this.init()
      this.pageSize = pageSize
      this.searchData.PageSize = pageSize
      this.getTableData()
    }
  }
}
</script>

<style lang="less" scoped>
.search-table-page {
  padding: 20px;
  min-height: 85vh;
  background-color: #fff;
  .row-operation {
    margin-bottom: 20px;
    .col-right {
      text-align: right;
      .spteen {
        margin-left: 5px;
      }
    }
  }
}
</style>
